var page = 1;
$(function () {
    var channel = getQueryString("channel");
    getExchangeRecode();
    $(".back-wrapper").click(function () {
        location.href = "./exchange.html?channel="+channel;
    });
    $(".home-wrapper").click(function () {
        location.href = "../index.html?channel="+channel;
    });
    scrollEvent();
});

function getExchangeRecode() {
    $.ajax({
        type:'get',
        url:BASE_URl + "record/exchange?page="+page,
        success:function (data) {
            if(data.success){
                $(".load-wrapper").hide();
                page ++;
                DrawExchangeRecode(data.data);
            }
        }
    });
}

function DrawExchangeRecode(data) {
    if(data.length != 0){
        var html = "";
        for(var i = 0;i < data.length;i++){
            html += `<li class="border-1px">
                            <div class="title-and-prod clearfix">
                                <div class="title fl">${data[i].title}</div>
                                <div class="prod fr">${data[i].prod}</div>
                            </div>
                            <div class="date">${data[i].date}</div>
                        </li>`;
        }
        $(".exchange-content ul").append(html);
    }else{
        $(".nor-more").show();
    }
}

function scrollEvent() {
    window.onscroll = function(){
        var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;  //获取滚动的距离
        var totalHeight = $(".exchange-wrapper").height();
        var clientHeight = document.body.clientHeight && document.documentElement.clientHeight;
        if(scrollTop + clientHeight == totalHeight){
            $(".nor-more").hide();
            $(".load-wrapper").show();
            getExchangeRecode();
        }
    };
}